<?php
	include("includes/connect_db.php"); 
	if ($_get['page'] == "autostart") {
		passthru("net start > service.log");
		$handle = fopen("service.log", "r");
		while (!feof($handle))
		{
		   $baristeks = fgets($handle);
		   if (substr_count($baristeks, 'Gammu SMSD Service (GammuSMSD)') > 0)
		   {
		     $status = 1;
		   }
		}
		fclose($handle);
		if ($status == 0) {
			passthru('C:\Gammu\bin\gammu-smsd -c smsdrc -s');
		}
	
	} else {
		$sql_autostart = "SELECT * FROM tb_autostart";
		$query_autostart = mysql_query($sql_autostart);
		$autostart = mysql_fetch_array($query_autostart);
		if ($autostart['autostart'] == "1") {
			passthru("net start > service.log");
			$handle = fopen("service.log", "r");
			while (!feof($handle))
			{
			   $baristeks = fgets($handle);
			   if (substr_count($baristeks, 'Gammu SMSD Service (GammuSMSD)') > 0)
			   {
			     $status = 1;
			   }
			}
			fclose($handle);
			if ($status == 0) {
				passthru('C:\Gammu\bin\gammu-smsd -c smsdrc -s');
			}
		}
	}
?>